const fs = require("fs");
const {sequelize} = require("../db");


//搜索所有的模型文件
function searchFiles(){
    let files=fs.readdirSync(__dirname);
    return files.filter(name=>{
        return name.endsWith('.js') && name!=='index.js';
    });
    
}

function registerModel(files){
    let obj={};

    files.forEach(name=>{
        let key=name.substring(0,name.length-3);
        obj[key]=require('./'+key);
    })
    console.log(obj);
    return obj;
}



let files = searchFiles();
let obj =registerModel(files);


obj.sync = async () => {
    return await sequelize.sync({force:true});
};
 

module.exports = obj ;

